package com.dorm.cj.extension.container;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Service;

/**
 * BeanFactoryAware获取容器对象
 */
@Service
public class TestBeanFactoryAware implements BeanFactoryAware {

    private BeanFactory beanFactory;

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    public void test() {
        TestService testService = (TestService) beanFactory.getBean("testService");
        System.out.println(testService.getName("======testService=========="));
    }

}
